package cn.edu.lcvc.ebuy_lyj.web.controler.backstage;

import cn.edu.lcvc.ebuy_lyj.service.AdminBean;
import cn.edu.lcvc.ebuy_lyj.model.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;


@Controller
@RequestMapping(value = "/backstage")
public class LoginLogoutController {
    @Autowired
    private AdminBean adminBean;//创建并初始化业务Bean

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public String login(String username, String password, HttpSession session){
        String url=null;
        if (adminBean.login(username,password)) {//调用业务Bean的方法
            Admin admin=adminBean.getAdmin(username);
            session.setAttribute("admin",admin);
            return "redirect:/jsp/backstage/main.html";
        } else {
            return "redirect:/jsp/backstage/login.jsp";

        }

    }
    @RequestMapping(value = "/logout",method = RequestMethod.GET)
    public String logout(HttpSession session) {
        session.removeAttribute("admin");
        return "redirect:/jsp/backstage/login.jsp";

    }

}
